﻿using UnityEngine;
using System.Collections;

public class Ball : MonoBehaviour {
    private Rigidbody rb;
    public Transform paddle;
    private const float RESET_Y = -19.5F;
    public float speed;
	// Use this for initialization
	void Start () {
        rb = GetComponent<Rigidbody>();
        Vector3 pos = transform.position;
        pos.x = paddle.position.x;
        pos.y = RESET_Y;
        transform.position = pos;
    }
	
	// Update is called once per frame
	void Update () {
        if (Input.GetKey(KeyCode.Space)/*鼠标左键*/)
        {
            Debug.Log(GM.instance.isPlaying);
            Vector3 speedNormalized = new Vector3(1f, 1f, 0).normalized; // 将向量单位化
            rb.velocity = speedNormalized * speed;
            GM.instance.isPlaying = true;
        }
        
	}
    private void OnTriggerEnter(Collider other)
    {
        
    

    }
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "brick")
        {
            Debug.Log(1);
            Destroy(collision.gameObject);
        }
        if (collision.gameObject.tag == "floor")
        {
            Debug.Log(2);
            Destroy(gameObject);
        }
    }
}
